package com.yfl.tingyu.controller;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yfl.tingyu.pojo.Host;
import com.yfl.tingyu.pojo.HostPower;
import com.yfl.tingyu.service.impl.HostServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2020-05-29
 */
@Controller
@RequestMapping("/host")
public class HostController {

    @Autowired
    private HostServiceImpl hostService;


    @RequestMapping("/hostManager")
    public String hostManager(){
        return "hostManager";
    }

    @RequestMapping("/list")
    @ResponseBody
    public Map<String, Object> list(@RequestParam  Map<String,Object> params){


        Map<String, Object> mapIPage = hostService.selectHosts(params);

        return mapIPage;
    }

    //修改权重
    @RequestMapping("/changeStrong")
    @ResponseBody
    public Boolean changeStrong(String strong,Integer hid){

        Host host=new Host();
        host.setHid(hid);
        host.setStrong(strong);
        boolean result = hostService.updateById(host);

        System.out.println("结果"+result);
        return  result;
    }

    //添加主持人
    @RequestMapping("/insert")
    @ResponseBody
    public Boolean insertHost(Host host){

        //设置注册时间
        LocalDateTime now = LocalDateTime.now();
        host.setStarttime(now);

        boolean save = hostService.save(host);

        return  save;
    }

    //账号禁用启用设置
    @RequestMapping("/changeStatus")
    @ResponseBody
    public Boolean changeStatus(Integer hid,String status){

        String sta="";
        if (status.equals("0")){
            sta="1";
        }
        if (status.equals("1")){
            sta="0";
        }

        Host host=new Host();
        host.setHid(hid);
        host.setStatus(sta);
        boolean result = hostService.updateById(host);
        return result;
    }

    //权限设置
    @RequestMapping("/hostPowerSet")
    @ResponseBody
    public Boolean hostPowerSet(HostPower hostPower){


        System.out.println("hostpower:"+hostPower);
        return  null;
    }

    //删除主持人
    @RequestMapping("/deleteHost")
    @ResponseBody
    public Boolean deleteHost(Integer[] hids){

        QueryWrapper<Host> qw=new QueryWrapper<>();
        qw.in("hid",hids);
        boolean remove = hostService.remove(qw);
        return remove;
    }
}

